package cn.com.vastbase.hibernate.sample.id.entity;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import java.io.Serializable;
import java.util.Objects;

@Getter
@Setter
@ToString
@Entity(name = "SystemUser")
public class SystemUser {

    @EmbeddedId
    private PK pk;

    private String name;


    @Getter
    @Setter
    @ToString
    @Embeddable
    public static class PK implements Serializable {

        private String subsystem;

        private String username;

        public PK(String subsystem, String username) {
            this.subsystem = subsystem;
            this.username = username;
        }

        private PK() {
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }
            PK pk = (PK) o;
            return Objects.equals(subsystem, pk.subsystem) &&
                    Objects.equals(username, pk.username);
        }

        @Override
        public int hashCode() {
            return Objects.hash(subsystem, username);
        }
    }
}

